package day07;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 需求:
 * <<主持人大赛>>有N 名评委给选手打分,要求分数范围为0到100之间的浮点数
 * 选手懂得最终得分为:去掉最高分的和最低分后的N-2名评委的平均分
 * 训练目标:方法的设计
 */
public class CalTotalAvg {
    public static void main(String[] args) {
        double[] scores = inputData(6);
        double avg = calAvg(scores);
        System.out.println("平均分为:" + avg);


    }

    //录入评委的评分

    public static double[] inputData(int count) {
        Scanner scan = new Scanner(System.in);
        double[] scores = new double[count];
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请输入第" + (i + 1) + "位评委的分数");
            scores[i] = scan.nextDouble();
        }
        return scores;
    }


    public static double calAvg(double[] scores) {
        double total = calTptal(scores);//获取最高分和最低分之后的总分
        double avg = total / (scores.length-2);
        return avg;
    }


    public static double calTptal(double[] scorse){
        double total = 0.0;
        double max = scorse[0];
        double min = scorse[0];
        for (int i = 0 ; i <scorse.length ; i++){
            if (scorse[i]> max){
                max = scorse[i];
            }
            if (scorse[i]<min){
                min = scorse[i];
            }
            total += scorse[i];

        }

        return total - max - min;

    }


}
